package com.mfangsoft.zhuangjialong.common.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtils;


public class BeanUtilsExtends extends BeanUtils {

	
	static {
		
		ConvertUtils.register(new DateConvert(), java.util.Date.class);
		
	}
	
	public static void copyProperties(Object dest, Object orig)
	        throws IllegalAccessException, InvocationTargetException {
		BeanUtils.copyProperties(dest, orig);
	    }
	
	public static Map<String, Object> objectToMap(Object obj){    
        if(obj == null){    
            return null;    
        }   
  
        Map<String, Object> map = new HashMap<String, Object>();    
  
        Field[] declaredFields = obj.getClass().getDeclaredFields();    
        for (Field field : declaredFields) {    
            field.setAccessible(true);  
            try {
				map.put(field.getName(), field.get(obj));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}  
        }    
  
        return map;  
    }   
	
}
